package com.burt.web.controllers;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.burt.web.service.TestService;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.Session;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.WebApplicationContext;

/**
 * Created by Burt
 * on 27/4/17.
 * Description:
 */
@Controller
public class TestRController {
    private static final Logger logger = LoggerFactory.getLogger(TestRController.class);

    @Autowired
    private WebApplicationContext context;

    @Autowired
    private RedisTemplate<String, Session> redisTemplate;

    @Autowired
    private TestService testService;


    @RequestMapping(value = "/r/webSocketPushMsg/{userId}")
    @ResponseBody
    public String webSocketPushMsg(@PathVariable String userId ,String message){
        Session session = redisTemplate.opsForValue().get(userId);
        try {
            session.getBasicRemote().sendText(message);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

//    @RequestMapping(value="/test/query")
//    @ResponseBody
//    public String query(int id) {
//        return userMapper.selectByPrimaryKey(id).getUserName();
//    }
}
